package com.hongguowei.lambda;

public class LambdaTest {
    public static void main(String[] args) {
        //无参数无返回值
        If1 c = () -> System.out.println("无返回值");
        c.test();
        //一个参数有返回值
        If3 if3 = (a) -> {
            return a;
        };
        System.out.println("有返回值" + if3.test3(8));
        //多个参数有返回值
        If2 if2 = (int a, int b) -> {
            return a - b;
        };
        System.out.println("有返回值" + if2.test2(8, 2));
        //方法的引用  对象:方法
        //假如是static方法 类名:方法
        LambdaTest lambdaTest = new LambdaTest();
        If3 if31 = lambdaTest::testA;
        If3 if32 = LambdaTest::testB;
        System.out.println(if31.test3(5));
        System.out.println(if32.test3(8));
    }

    public int testA(int a) {
        return a - 2;
    }

    public static int testB(int a) {
        return a - 2;
    }

    interface If1 {
        void test();
    }

    interface If2 {
        int test2(int a, int b);
    }

    interface If3 {
        int test3(int a);
    }

}
